package com.ropa.java.produder_demo;

import cn.hutool.core.map.MapUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.lang.management.ManagementFactory;
import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class ProducerApp {
    public static void main(String[] args) {
        SpringApplication.run(ProducerApp.class, args);
    }



    @GetMapping("info")
    public String getInfo(@Value("${server.port}") String port){

        return String.format("hello from  port:%s - pid:%d",port, Thread.currentThread().getId());
    }

    @PostMapping(value = "url-encoded"
            //,            consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE}
            )
    public Map<String,?> urlEncoded(@RequestBody String body,
                                    @RequestParam("Mobile") String mobile,
                                    @RequestParam("Content") String Content,
                                    @RequestParam("CorpID") String CorpID
                                    ){
        HashMap<String, String> res = MapUtil.of("body", body);
        res.put("mobile", mobile);
        res.put("content", Content);
        res.put("corpId", CorpID);
        return res;
    }
}
